<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%String path = request.getContextPath();%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %> 
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>小贷合同补录</title>
<jsp:include page="../../import.jsp" flush="true"/>
</head>
<body class="iframeBody">
<div class="Wrapper">
	<div class="searchArea">
		<form id="searchBar">
			<div class="fieldset1 clearFix">
				<div class="FXBR">
					<div class="fieldBox">
						<div class="label">客户ID</div>
						<div class="field">
							<input name="cstId" id="cstId" type="text" class="ui-textbox" value="" ligerui="width: 160">
						</div>
						<div class="label">合同号</div>
						<div class="field">
							<input name="contract" id="contract" type="text" class="ui-textbox" value="" ligerui="width: 160">
						</div>
					</div>
				</div>

				<div class="btnsBox formBtns notRight">
					<div class="btnsBox formBtns notRight">
						<span id="searchBtn" onclick="searchBtn()" class="sq-button-round">查询</span>
						<span id="clearBtn" onclick="clearBtn();" class="sq-button-round">清空</span>
						<span id="arbitrateContract" onclick="arbitrateContract(1);"
							  class="sq-button-round">补录北海仲裁合同(跳过已经存在)
						</span>
						<span id="arbitrateContract0" onclick="arbitrateContract(0);"
							  class="sq-button-round">补录北海仲裁合同(先作废后生成)
						</span>
					</div>
				</div>

			</div>
        </form>
    </div>
</div>
<div id="mcrContractGrid" class="sq-grid"></div>

<script type="text/javascript">
	var grid = null;
	$(function () {
	    initForm();
		initGrid();
	});

	//初始化表单
	function initForm(){
		$("#searchBar").ligerForm();
	}

	//初始化列表
	function initGrid(){
		$("#mcrContractGrid").ligerGrid({
			url: '<%=path%>/mcr/contract/initList.do',
			method : 'post',
			isSingleCheck: false,
			parms:getSearchParams(),
			columns: [
				{ display: '客户姓名', name: 'cstNm', width: 120 ,  align:'center', enabledSort:true,},
				{ display: '客户Id', name: 'cstId', width: 120 ,  align:'center', enabledSort:true,},
				{ display: '账单Id', name: 'id', width: 160, align:'center', enabledSort:true },
				{ display: '合同号', name: 'crCntNo', width: 160, align:'center', enabledSort:true },
				{ display: '贷款类型', name: 'crTypCd', width: 120, align:'center', enabledSort:true },
				{ display: '机构名称', name: 'loanName', width: 120, align:'center', enabledSort:true },
				{ display: '放款日', name: 'crDt', width: 120, align:'center', enabledSort:true ,
					render: function (rowdata, rowindex, value){
						return renderDate(rowdata, rowindex, value);
					}
				},
				getGridOperColumnContent()
			],
			pageSize:10,
			root:'rows',
			record:'total',
			hideLoadButton : true,
			width: '100%',
			height:'100%',
			heightDiff:-2,
			checkbox:true,
			rownumbers:true
		});
		grid = liger.get("mcrContractGrid");
		grid.setHeight(100);
	}

	//Grid操作列
	function getGridOperColumnContent(){
		return {
			display: '操作',
			isSort: false,
			width: 280,
			render: function (rowdata, rowindex, value) {
				var resultStr = "";
				if (rowdata.contractTypeCd === 'CON004'){
					var h = '<a class="sq-button-hasicon" href="javascript:additionalContract(';
					h += "'" + 'CON004' + "'";
					h += ",'" + rowdata.cstId + "'";
					h += ",'" + rowdata.crCntNo + "'";
					h += ")\"><i class=\"sqBtnIco_4\"></i>补录云信单一合同</a>";
					resultStr = h;
				}
				if (rowdata.contractTypeCd === 'CON005'){
					var h = '<a class="sq-button-hasicon" href="javascript:additionalContract(';
					h += "'" + 'CON005' + "'";
					h += ",'" + rowdata.cstId + "'";
					h += ",'" + rowdata.crCntNo + "'";
					h += ")\"><i class=\"sqBtnIco_4\"></i>补录云信合同</a>";
					resultStr = h;
				}
				if (rowdata.contractTypeCd === 'CON009'){
					var h = '<a class="sq-button-hasicon" href="javascript:additionalContract(';
					h += "'" + 'CON009' + "'";
					h += ",'" + rowdata.cstId + "'";
					h += ",'" + rowdata.crCntNo + "'";
					h += ")\"><i class=\"sqBtnIco_4\"></i>补录云信七期合同</a>";
					resultStr = h;
				}
				if (rowdata.contractTypeCd === 'CON002'){
					var k = '<a class="sq-button-hasicon" href="javascript:additionalContract(';
					k += "'" + 'CON002' + "'";
					k += ",'" + rowdata.cstId + "'";
					k += ",'" + rowdata.crCntNo + "'";
					k += ")\"><i class=\"sqBtnIco_4\"></i>补录我司合同</a>";
					resultStr = k;
				}
				if (rowdata.contractTypeCd === 'CON006'){
					var k = '<a class="sq-button-hasicon" href="javascript:additionalContract(';
					k += "'" + 'CON006' + "'";
					k += ",'" + rowdata.cstId + "'";
					k += ",'" + rowdata.crCntNo + "'";
					k += ")\"><i class=\"sqBtnIco_4\"></i>补录五矿合同</a>";
					resultStr = k;
				}
				return resultStr;
			}
		};
	}

	// 补录合同
	function additionalContract(type,cstId,contract){
		// 防失误按钮
		$.ligerDialog.confirm("确认是否补录合同？", function (flag) {
			if (flag === false)return;
			if (StringUtils.isEmpty(cstId)){
				top.$.ligerDialog.SQalert({content: "客户Id不能为空",SQ_type: "error"});
				return;
			}
			if (StringUtils.isEmpty(contract)){
				top.$.ligerDialog.SQalert({content: "合同号不能为空",SQ_type: "error"});
				return;
			}
			var _url = '<%=path%>/mcr/contract/additionalContract.do';
			AjaxUtils.ajaxPost(_url, {cstId:cstId,contractType:type,contract:contract}, function (msg) {
				if(msg.success === 1){
					top.$.ligerDialog.SQalert({content: "合同补录成功",SQ_type: "success"});
				}else{
					top.$.ligerDialog.SQalert({content: "合同补录失败",SQ_type: "error"});
				}
			});
		});
	}

	// 补录仲裁合同
	function arbitrateContract(arbitrateType){
		if (StringUtils.isEmpty(arbitrateType)){
			top.$.ligerDialog.SQalert({content: "仲裁合同类型为空",SQ_type: "error"});
			return;
		}

		dialogForAddMain = $.ligerDialog.SQopen({
			width: 850,
			height:400,
			title : '导入客户信息',
			url:'<%=path%>/mcr/contract/toMcrArbitrateContract.do?arbitrateType='+arbitrateType,
			onClosed: function () {
			},
			onLoaded: function () {
				_subWin=dialogForAddMain.get("_subWin");
			}
		});
	}

	//清空按钮事件
	function clearBtn(){
		var form = new liger.get("searchBar");
		form.setData({  //重置select等特殊表单
			"cstId":"",
			"contract":""
		});
	}

	//查询按钮事件
	function searchBtn(){
		var form = new liger.get("searchBar");
		var data = form.getData();
		for (name in data){
			grid.setParm(name,data[name]);
		};
		grid.reload();
	}

	//查询参数
	function getSearchParams(){
		var form = new liger.get("searchBar");
		var data = form.getData();
		return data;
	}

	//格式化时间
	function renderDate(rowdata, index, value) {
		var dateStr = "";
		if (null != value) {
			var date = new Date(value);
			//dateStr = DateUtils.formatDate(date, "yyyy-MM-dd hh:mm");
			dateStr = DateUtils.formatDate(date, "yyyy-MM-dd");
		}
		return dateStr;
	}

</script>
</body>
</html>